﻿/*
公告新增编辑
*/ 
//
angular.module('operateNewAddEdit', ['knowledgeSelector'])
 .directive("operateNewAddEdit", ["$rootScope", "$stateParams", "$timeout", "operatepathservice", function ($rootScope, $stateParams, $timeout, OS) {
     return {
         restrice: "AE",
         scope: {
             isSaveBtn: "=", // 是否正在请求中
             otherNew: "=", //单独的二级运营对象
             config: "=", //富文本配置           
             onSave: "&",     //保存对象到服务器          
             onCancel: "&"    // 取消保存方法
             , knowChapter: '='
         },
         templateUrl: "/system/directive/operate/operate_new_add_edit.html",
         link: function (scope, element, attr) {
             /*****************************************************************************************/
             //初始置顶
             if (scope.otherNew.isTop == undefined) {
                 scope.otherNew.isTop = "0";
             }
             //置顶
             scope.putTop = function () {
                 if(scope.otherNew.isTop=="0"){
                    scope.otherNew.isTop="1";
                 }else{
                    scope.otherNew.isTop="0";
                 }
             }
             //打开文件选择器
             scope.openChapter = function () {
                 scope.knowChapter.ksfList = [];
                 scope.knowChapter.isShow = true;
             }
             //选择器关闭后的回调
             scope.onCallback = function () {
                 if (scope.knowChapter.ksfList.length > 0) {
                     var html = "";
                     if (scope.knowChapter.ksfList[0].fileType != undefined && scope.knowChapter.ksfList[0].fileType != null) {
                         //文件类型
                         var filetype = scope.knowChapter.ksfList[0].fileType.toLowerCase();
                         //文件预览地址
                         var url = scope.knowChapter.ksfList[0].filepreview;
                         if (url == undefined || url == null || url.length <= 0) {
                             url = scope.knowChapter.ksfList[0].fileurlonly;
                         }
                         switch (scope.knowChapter.ksfList[0].fileType) {
                             case "mp4":
                             case "flv":
                             case "mp3":
                             case "f4v":
                             case "m3u8":
                             case "webm":
                             case "ogg":
                                 html = "<iframe src='" + url + "' frameborder='0' allowfullscreen></iframe>";
                                 break;
                             case "jpg":
                             case "jpge":
                             case "png":
                             case "gif":
                                 html = "<img src='" + url + "' />";
                                 break;
                             default:
                                 html = "<a href='" + url + "' target='_blank'>" + scope.knowChapter.ksfList[0].fileName + "</a>";
                                 break;
                         }
                     } else {
                         html = "<a href='" + url + "' target='_blank'>" + scope.knowChapter.ksfList[0].fileName + "</a>";
                     }
                     scope.otherNew.pubContent += html;
                 }
             }
             /****************************************************************************************/
             // 是否紧急切换
             scope.radiosel = function () {
                 if (scope.otherNew.pubCritical) {
                     scope.otherNew.pubCritical = false;
                 } else {
                     scope.otherNew.pubCritical = true;
                 }
             }
             // 学员端可见切换
             scope.radioPubType = function () {
                 if (scope.otherNew.pubType == "1") {
                     scope.otherNew.pubType = ""; //管理端可见
                 } else {
                     scope.otherNew.pubType = "1"; //学员端可见
                 }
             }
             // 取消
             scope.btnCancel = function () {
                 scope.onCancel();
             }
             scope.res = "";
             //保存分配企业
             scope.btnSave = function () {
                 scope.onSave();
             }
         }
     }
 } ])

